Using the Text Block nodes

Use the Text Block nodes to show a small amount of text in your application. Text block node uses the font you select to render the text. Use Text Block 3D to show text in 3D space and Text Block 2D to show text in 2D space.

The default font in Kanzi is Fira Sans Regular. It is stored in <KanziInstallation>/Studio/Asset Library/Fonts. When you want to use your own font, import it to your Kanzi Studio project. See Importing fonts.

Note that in order to properly render text content you have to use a font that includes the glyphs of the languages you want to include in your Kanzi application.

When you want the background of the text block nodes to be transparent, you need to render the nodes in the scene graph of your Kanzi application in the correct order. See Rendering transparent nodes.

Adding text to your application

To add text to your application:

  1. In the Project press Alt and right-click the node where you want to show text and select either Text Block 3D, or Text Block 2D.
    Note that you can create a 3D node only inside 3D nodes, and 2D node only inside 2D nodes.
  2. In the Properties in the Text property enter the text you want to show. To add a new line press Shift+Enter.
    Use the Text Block nodes to show a small amount of text in your application. When the text is longer than a text block can show, by default Kanzi shows ellipsis. Add and set the Overflow property to show custom text.
  3. In the Properties set the text block properties to make the text look the way you want it to look..
    For example, set the Font Size property to define the size of the text, and Font Color to define the color of the text.
  4. (Optional) In the Font property select the font you want to use.
    The default font in Kanzi is Fira Sans Regular. It is stored in <KanziInstallation>/Studio/Asset Library/Fonts. When you want to use your own font, import it to your Kanzi Studio project. See Importing fonts.

Changing the size of text dynamically

To dynamically change the size of text in a Text Block node, use the Scale property field of either Render Transformation or Layout Transformation properties, instead of the Font Size property. For example, use this approach when you want to animate the size of text in a Text Block node.
When you use the Font Size property to dynamically scale the text, Kanzi creates multiple textures for different font sizes and does not release them from the memory.

Setting the background of a Text Block 2D

Use brushes to set the background of 2D nodes. In Kanzi all 2D nodes by default have transparent background.

To set the background:

  1. Create a Color Brush, a Texture Brush, or a Material Brush. See Using brushes.
  2. In the Project select the 2D node the background of which you want to paint.
    Note that you can set only the background of 2D nodes.
  3. In the Properties click , add the Background Brush property, and select the brush you created in the first step.

Using Text Block 3D in the API

To create a Text Block 3D object:

// Create a Text Block 3D node named Text block.
TextBlock3DSharedPtr textBlock = TextBlock3D::create(domain, "Text block");

To set the font of a text block:

// Set the font used by the text block node using the resource ID.
textBlock->setFontResourceID(ResourceID("MyFont"));

To add the text shown by a text block:

// Set the content of the text block node to read Hello world!.
textBlock->setText("Hello\nworld!");

To adjust the appearance of the text:

// Set the style of the text shown by the text block node.
// Set the size of the font to 90.0f.
textBlock->setFontSize(90.0f);
// Set the color of the font to blue.
textBlock->setFontColor(KanziThemeBlue);
// Align the text in the text block to the right.
textBlock->setTextHorizontalAlignment(TextBlockConcept::TextHorizontalAlignmentRight);

For details, see the API reference.

Using Text Block 2D in the API

To create a Text Block 2D object:

// Create a Text Block 2D object named Text layer.
TextBlock2DSharedPtr textLayer = TextBlock2D::create(domain, "Text layer");

To set the font of a text block:

// Set the font used by the text block using the resource ID.
textLayer->setFontResourceID(ResourceID("MyFont"));

To add the text shown by a text block:

// Set the content of the text block to read Hello world!.
textLayer->setText("Hello\nworld!");

To adjust the appearance of the text:

// Set the style of the text shown by the text block.
// Set the line spacing to 1.5f.
textLayer->setLineSpacing(1.5f);
// Set the size of the font to 36.0f.
textLayer->setFontSize(36.0f);
// Set the color of the font to blue.
textLayer->setFontColor(KanziThemeBlue);
// Align the text in the text block to the right.
textLayer->setTextHorizontalAlignment(TextBlockConcept::TextHorizontalAlignmentRight);

For details, see the API reference.

See also

Size of the glyph cache texture

Importing fonts